<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%>

<%
	request.setAttribute("title", "活动详情");
	request.setAttribute("modelConfigPath", "acti");
%>

<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<style type="text/css">
.content {
	margin-bottom: 28px;
}
</style>
<t:panel cssClass="panel-flat form-detailed" customBody="true" customHead="true">
	<div class="detailed-navbar-content panel-body content">
		<t:form commandName="activity" action="/admin/acti/activity/save" method="post" cssClass="form-horizontal">
			<div class="hide">
				<t:hidden path="id" />
				<t:hidden path="actiImg"/>
				<t:hidden path="deleteMark" />
				<t:hidden path="confirmState" />
				<t:hidden path="createDate" />
				<t:hidden path="createUserName" />
				<t:hidden path="createUserId" />
			</div>
			<t:formgroup>
				<t:label path="name" cssClass="col-sm-2" />
				<t:input path="name" colClass="col-sm-4" />
				<t:label path="object" cssClass="col-sm-2" />
				<t:input path="object" colClass="col-sm-4" />
			</t:formgroup>
			<t:formgroup>
				<t:label path="startDate" cssClass="col-sm-2" />
				<t:input type="date" path="startDate" colClass="col-sm-4" />
				<t:label path="endDate" cssClass="col-sm-2" />
				<t:input type="date" path="endDate" colClass="col-sm-4" />

			</t:formgroup>
			<t:formgroup>
				<t:label path="reward" cssClass="col-sm-2" />
				<t:input path="reward" colClass="col-sm-2" />
				<t:select2 path="rewardCurrency" colClass="col-sm-2" />
				<t:label path="exchange" cssClass="col-sm-2" />
				<t:input path="exchange" colClass="col-sm-4" />
			</t:formgroup>
			<t:formgroup>
				<t:label path="actiType" cssClass="col-sm-2" />
				<t:select2 path="actiType" colClass="col-sm-4" />
				<t:label path="actiState" cssClass="col-sm-2" />
				<t:select2 path="actiState" colClass="col-sm-4" />
			</t:formgroup>
			<t:formgroup>
				<t:label path="actiUrl" cssClass="col-sm-2" />
				<t:input path="actiUrl" colClass="col-sm-4" />
			</t:formgroup>
			<t:formgroup>
				<t:label path="content" cssClass="col-sm-2" />
				<t:textarea path="content" style="height:100px;" colClass="col-sm-10" />
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="actiImg" cssClass="col-sm-4" />
					<div class="col-sm-4">
						<c:if test="${activity.actiImg!=null && activity.actiImg!=''}">
							<img style="width: 100px; height: 80px;" id="smallPicShow" src="${tfn:getFileUrl(activity.actiImg)}" />
						</c:if>
						<c:if test="${activity.actiImg ==null || activity.actiImg==''}">
							<img style="width: 100px; height: 80px;" id="smallPicShow" src="<c:url value='/images/we/invitationIndex/bg1.jpg' />" />
						</c:if>
					</div>
					<div class="col-sm-4">
						<label>加载进度</label>
						<div style="width: 100px; height: 10px; margin-top: 0.5rem; border: 2px solid #afafaf; border-radius: 15px;" class="smallParent">
							<div style="width: 0px; height: 7px; background-color: #afafaf" class="smallProgress"></div>
						</div>
						<button type="button" class="btn-info" id="deleteSmallPic" style="padding-left: 10px; border-radius: 6px; margin-top: 1rem">删除图片</button>
					</div>
				</div>
			</t:formgroup>
		</t:form>
	</div>
	<div class="navbar-fixed-bottom">
		<t:panelFoot headingBtnCssClass="heading-btn pull-right-important">
			<t:button icon="icon-floppy-disk" onclick="saveData()" cssClass="btn-info" csize="sm">保存</t:button>
		</t:panelFoot>
	</div>
</t:panel>

<script type="text/javascript">
function saveData() {
	
	if (loadPrice() == false) {
		return;
	}

	
	if (!$("form:first").valid()) {
		return;
	}
	$("form:first").submit();
}

/*--------------------选择币种后，不同币种的不同验证与错误提示-------------------- */
$(function() {

	$("#reward").on("change", function() {
		loadPrice();
	})

	$("#rewardCurrency").on("change", function() {
		loadPrice();
	})
});

function loadPrice() {
	var reward = $("#reward").val();
	var rewardCurrency = $("#rewardCurrency").val();

	if (rewardCurrency == "yuan") {
		var reg = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0){1}$)|(^\d\.\d{1,2}?$)/;
		if (!reg.test(reward)) {
			var errorConfig = {
				content : "请输入正整数或1-2位小数",
				alignTo : 'target',
				alignX : "left",
				alignY : 'center',
				showOn : 'none',
				bgImageFrameSize : 9,
				offsetX : 5
			};
			$("#reward").poshytip(errorConfig).poshytip("show");

			return false;
		} else {

			$("#reward").poshytip("destroy");
			return true;
		}
	}

	if (rewardCurrency == "jindou") {
		var reg = /(^((\d{1,9}))$)/;
		if (!reg.test(reward)) {
			var errorConfig = {
				content : "请输入正整数",
				alignTo : 'target',
				alignX : "left",
				alignY : 'center',
				showOn : 'none',
				bgImageFrameSize : 9,
				offsetX : 5
			};
			$("#reward").poshytip(errorConfig).poshytip("show");
			return false;
		} else {
			$("#reward").poshytip("destroy");
			return true;
		}
	}
};


/*-------------------- 上传图片 点击就加入云端服务器---------------------- */
$(function() {
	$("#smallPicShow").on('click', function(e) {
		$(".smallProgress").width(0);
		$("#actiImg").startCosFileUpload({
			fillImg : "#smallPicShow",
			progressCallback:function(curr, sha1){
				$(".smallParent").show();
				$(".smallProgress").width(0);
				$(".smallProgress").width(sha1*96);
			}
		});
	});
});

/*--------------------删除上传的图片,页面和数据库都删除---------------------- */
$(function() {
	$("#deleteSmallPic").on('click',function(e) {
	$(".smallProgress").width(0);
	$("#smallPicShow").attr("src",$.getVirtualPath()+ "/images/we/invitationIndex/bg1.jpg");
	$("#actiImg").val("");
		console.log(result);
	});
});

</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formpickers.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/editor/ueditor.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/tools/upload-cos.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/contentFooter.jsp"%>